package com.fenda.jetpacknavigation.roomdata;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Update;

import java.util.List;

import io.reactivex.Completable;
import io.reactivex.Flowable;
import io.reactivex.Maybe;


//结合LiveData的话需要添加LiveData的观察
@Dao
public interface UserDao {
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    Completable insertName(User...users);

    @Update
    Completable updateName(User...users);

    @Delete
    void deleteNames(User...users);

    @Query("DELETE FROM User")
    Completable deleteAll();

    @Query("SELECT * FROM User ORDER BY ID ASC")
    Flowable<List<User>> getAllNames();

    @Query("SELECT * FROM User WHERE ID = :ID LIMIT 1")
    Flowable<User> getUser(int ID);

    @Query("SELECT * FROM User WHERE ID BETWEEN :minID AND :maxID")
    Flowable<List<User>> getUerById(int minID,int maxID);
}
